/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.swta;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;

/**
 *
 * @author JKorreck
 */
public class InDecreasePackageItemPanel extends Panel {

    Component parent;
    MyItemPackage packageToEdit;
    MyItem actItem;
    

    /**
     * @param id
     *            component id
     * @param model
     *            model for contact
     */
    public InDecreasePackageItemPanel(String id, String packageID, IModel model, Component parent) {
        super(id, model);
        this.actItem = (MyItem) model.getObject();
        this.parent = parent;
        this.packageToEdit = MyItemPackageManager.getInstance().getItemPackage(packageID);

        add(new AjaxLink("increase") {

            @Override
            public void onClick(AjaxRequestTarget target) {
                System.out.println("INCREASE" + InDecreasePackageItemPanel.this.actItem.getId() + "OF: " + InDecreasePackageItemPanel.this.packageToEdit.getId());
                MyItemPackageManager.getInstance().getItemPackage(packageToEdit.getId()).increaseItem(actItem.getId());
                System.out.println("PARENT: " + InDecreasePackageItemPanel.this.parent.getClassRelativePath().toString());
                target.addComponent(InDecreasePackageItemPanel.this.parent);
            }
        });

        add(new AjaxLink("decrease") {

            @Override
            public void onClick(AjaxRequestTarget target) {
                System.out.println("DECREASE" + InDecreasePackageItemPanel.this.actItem.getId() + "OF: " + InDecreasePackageItemPanel.this.packageToEdit.getId());
                MyItemPackageManager.getInstance().getItemPackage(packageToEdit.getId()).decreaseItem(actItem.getId());
                target.addComponent(InDecreasePackageItemPanel.this.parent);
            }
        });
    }
}
